package com.biz.primus.ms.commodity.dao.po;

import com.biz.primus.base.enums.commodity.IStatus;
import com.biz.primus.commodity.vo.backend.ISaleTagVo;
import com.biz.primus.ms.base.jpa.po.BaseEntity;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 商品销售标签
 *
 * @author david-liu
 * @date 2016年12月15日
 * @reviewer
 * @see
 */
@Entity
@Table(name = "pro_sale_tag")
public class SaleTag extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 4832975674570352636L;

    /**
     * 标签名
     */
    @Column(name = "tag_name",unique = true, length = 50)
    private String tagName;

    /**
     * 前台展示
     */
    @Column(name = "show_name",unique = true,length = 50)
    private String showName;

    /**
     * 标签图片
     */
    @Column(name = "tag_image")
    private String tagImage;

    /**
     * 标签
     */
    @Column
    private String tag;

    /**
     * 标签角标
     */
    @Column(name = "sub_tag", length = 50)
    private String subTag;

    /**
     * 显示顺序
     */
    @Column
    private Integer idx;

    /**
     * 后台备注
     */
    @Column
    private String note;

    /**
     * 启用状态
     */
    @Column
    private IStatus status;

    /**
     * 富文本
     */
    @Column
    private String editor;

    @ManyToMany
    @JoinTable(name = "pro_sale_tag_product",
            joinColumns = {@JoinColumn(name = "sale_tag_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "product_id", referencedColumnName = "id")})
    private List<Product> products;

    /**
     * 删除标识(默认是未删除)
     */
    @Column
    private Boolean deleteFlag = Boolean.FALSE;

    public List<Product> getProducts() {
        return products;
    }

    public SaleTag setProducts(List<Product> products) {
        this.products = products;
        return this;
    }

    public Boolean getDeleteFlag() {
        return deleteFlag;
    }

    public void setDeleteFlag(Boolean deleteFlag) {
        this.deleteFlag = deleteFlag;
    }

    public String getTagName() {
        return tagName;
    }

    public void setTagName(String tagName) {
        this.tagName = tagName;
    }

    public String getShowName() {
        return showName;
    }

    public void setShowName(String showName) {
        this.showName = showName;
    }

    public String getTagImage() {
        return tagImage;
    }

    public void setTagImage(String tagImage) {
        this.tagImage = tagImage;
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public String getSubTag() {
        return subTag;
    }

    public void setSubTag(String subTag) {
        this.subTag = subTag;
    }

    public Integer getIdx() {
        return idx;
    }

    public void setIdx(Integer idx) {
        this.idx = idx;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public IStatus getStatus() {
        return status;
    }

    public void setStatus(IStatus status) {
        this.status = status;
    }

    public String getEditor() {
        return editor;
    }

    public void setEditor(String editor) {
        this.editor = editor;
    }

    public void fromVo(ISaleTagVo iSaleTagVo) {
        if (iSaleTagVo.getId() != null){
            this.setId(Long.valueOf(iSaleTagVo.getId()));
        }
        this.setTagName(iSaleTagVo.getTagName());
        this.setShowName(iSaleTagVo.getShowName());
        this.setTag(iSaleTagVo.getTag());
        this.setSubTag(iSaleTagVo.getSubTag());
        this.setIdx(iSaleTagVo.getIdx());
        this.setNote(iSaleTagVo.getNote());
        this.setStatus(iSaleTagVo.getStatus());
    }
}
